package com.office.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.office.system.domain.SysStockRecords;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.office.common.annotation.Log;
import com.office.common.core.controller.BaseController;
import com.office.common.core.domain.AjaxResult;
import com.office.common.enums.BusinessType;
import com.office.system.domain.SysOffice;
import com.office.system.service.ISysOfficeService;
import com.office.common.utils.poi.ExcelUtil;
import com.office.common.core.page.TableDataInfo;

/**
 * 办公用品管理Controller
 * 
 * @author ruoyi
 * @date 2024-07-18
 */
@RestController
@RequestMapping("/system/office")
public class SysOfficeController extends BaseController
{
    @Autowired
    private ISysOfficeService sysOfficeService;

    /**
     * 查询办公用品管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:office:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysOffice sysOffice)
    {
        startPage();
        List<SysOffice> list = sysOfficeService.selectSysOfficeList(sysOffice);
        return getDataTable(list);
    }

    /**
     * 导出办公用品管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:office:export')")
    @Log(title = "办公用品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOffice sysOffice)
    {
        List<SysOffice> list = sysOfficeService.selectSysOfficeList(sysOffice);
        ExcelUtil<SysOffice> util = new ExcelUtil<SysOffice>(SysOffice.class);
        util.exportExcel(response, list, "办公用品管理数据");
    }

    /**
     * 获取办公用品管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:office:query')")
    @GetMapping(value = "/{officeId}")
    public AjaxResult getInfo(@PathVariable("officeId") Long officeId)
    {
        return success(sysOfficeService.selectSysOfficeByOfficeId(officeId));
    }

    /**
     * 新增办公用品管理
     */
    @PreAuthorize("@ss.hasPermi('system:office:add')")
    @Log(title = "办公用品管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysOffice sysOffice)
    {
        return toAjax(sysOfficeService.insertSysOffice(sysOffice));
    }

    /**
     * 修改办公用品管理
     */
    @PreAuthorize("@ss.hasPermi('system:office:edit')")
    @Log(title = "办公用品管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysOffice sysOffice)
    {
        return toAjax(sysOfficeService.updateSysOffice(sysOffice));
    }

    /**
     * 删除办公用品管理
     */
    @PreAuthorize("@ss.hasPermi('system:office:remove')")
    @Log(title = "办公用品管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{officeIds}")
    public AjaxResult remove(@PathVariable Long[] officeIds)
    {
        return toAjax(sysOfficeService.deleteSysOfficeByOfficeIds(officeIds));
    }

//    /**
//     * 添加入库记录
//     */
//    @PreAuthorize("@ss.hasPermi('system:office:addStock')")
//    @Log(title = "办公用品管理", businessType = BusinessType.INSERT)
//    @PostMapping("/stockRecords")
//    public AjaxResult addStockRecords(@RequestBody List<SysStockRecords> sysStockRecordsList) {
//        return toAjax(sysOfficeService.addStockRecords(sysStockRecordsList));
//    }
//
//    /**
//     * 获取办公用品的入库记录列表
//     */
//    @PreAuthorize("@ss.hasPermi('system:office:getStockRecords')")
//    @GetMapping("/{officeId}/stockRecords")
//    public AjaxResult getStockRecordsByOfficeId(@PathVariable("officeId") Long officeId) {
//        List<SysStockRecords> stockRecords = sysOfficeService.getStockRecordsByOfficeId(officeId);
//        return success(stockRecords);
//    }
}
